<?php
/**
 * Controller uvodnej stranky
 * @author Tomas Srna
 * @package bakalarka
 */

class IndexController extends Controller
{
	protected $resource = 'index';
	/**
	 * Akcia index
	 */
	function index()
	{
		$t = Template::instance();
			
		$t->title = L::selected()->dashboard;
		
		$user = Auth::instance()->getUser();
		
		$t->addHook('headEnd', "<link rel=\"stylesheet\" ".
			"type=\"text/css\" href=\"".APPBASE."css/form.css\" />");
		
		
		$g = new GravatarWriter();
		$t->properties_title = L::selected()->loggedIn;
		$t->properties = array(
			'' => $g->set($user->email).'<br/>'.L::selected()->gravatar,
			L::selected()->username => $user->username,
			L::selected()->email => $user->email,
			//L::selected()->group => $user->group,
		);
		if(property_exists($user, 'firstname'))
			$t->properties[L::selected()->firstname] = $user->firstname;
		if(property_exists($user, 'lastname'))
			$t->properties[L::selected()->lastname] = $user->lastname;
		if(property_exists($user, 'phone'))
			$t->properties[L::selected()->phone] = $user->phone;
		if(property_exists($user, 'address'))
			$t->properties[L::selected()->address] = $user->address;
		
		$ab = APPBASE;
		
		$t->buttons = array(
			new Button('pencil.png', L::selected()->profile, 
				"window.location.href='{$ab}profile';"),
			new Button('key.png', L::selected()->password, 
				"window.location.href='{$ab}passwd';"),
		);
		
		$t->text =  
			(Auth::instance()->getUser()->group == 'admin' ?
			'<div class="intersection"><h2>'.L::selected()->administer.'</h2>'.
			new Menu(array(
			new Link(L::selected()->users, 'admin', 'admin', 'user'),	
			new Link(L::selected()->acl, 'admin', 'admin', 'acl'),
			new Link(L::selected()->domains, 'admin', 'admin', 'domain'),
			new Link(L::selected()->hostings, 'admin', 'admin', 'hosting'),
			new Link(L::selected()->syslog, 'admin', 'admin', 'log'),
		)).'</div>' : '').
		'<div class="intersection"><h2>'.L::selected()->domains.'</h2>'.
				new DomainMenu().'</div>'.
		'<div class="intersection"><h2>'.L::selected()->hostings.'</h2>'.
				new HostingMenu().'</div>';
		
		$t->render('dashboard');
	}
}
